#ifndef COMMON_HEADER
#define COMMON_HEADER
#include <WinSock2.h>

#define MAXBUFFSIZE 64
#define MAXCONN 10
#define PORT "12345"
#define PORT1 "22345"
#define PORT2 "32345"
#define PORT3 "42345"
#define LOCALHOST "127.0.0.1"

#define USER_CONNECT 0
#define USER_RELEASE 1
#define USER_GETNODE 2
#define NODE_GETNUM 3

typedef struct _TOperationInfo {
	int op;
	int val;
} TOperationInfo;

typedef struct _TSocketInfo {
	WSAOVERLAPPED overlapped;
	ULONG recvBytes;
	ULONG flag;
	WSABUF buf;
	char internalBuffer[MAXBUFFSIZE];
} TSocketInfo;

typedef struct _TUserInfo {
	int id;
	void* param;
	struct _TUserInfo* father;
	struct _TUserInfo* left;
	struct _TUserInfo* right;
} TUserInfo;

TUserInfo* tUserInfo(int id = -1);
TSocketInfo* tSocketInfo(void);

void error(char* msg);

SOCKET createListenSocket(char* port, SOCKET* inSocket = NULL, bool block = false);
SOCKET createConnectSocket(char* port, char* ipaddr, SOCKET* inSocket = NULL);

bool addUser(TUserInfo* root, int id, TUserInfo** rootUser);
bool deleteUser(TUserInfo* root, int id, TUserInfo** rootUser);
bool find(TUserInfo* root, int id);

#endif